//ATM

var ATM = function (address){
    
    var _address = address;
    
    var _costumers = {};
    
    var _id = Math.floor(Math.random()*900000000) + 100000000;
    
    this.getId = function (){
        document.getElementById("messages").innerHTML= '<p>The ATM id is'+ _id + '</p>';
        return _id;
    };

    this.getAddress = function (){
        document.getElementById("messages").innerHTML = "The ATM number " +_id + " is located in "+ _address;
        return _address;
    };
    
    this.createCostumer = function (firstName, lastName){
        var costumer = new Costumer (firstName, lastName);
        _costumers[costumer.getId()] = costumer ;
        return costumer;
    };   
    
    this.deleteCostumer = function (costumerId){
        delete _costumers [costumerId];
        document.getElementById("messages").innerHTML = "The costumer " +costumerId + " has been deleted";

    };
    
    this.getCostumer = function (costumerId) {
        return _costumers[costumerId];
    }
    this.getCostumers = function (){
        return _costumers;
    }  
    document.getElementById("messages").innerHTML= '<p>The ATM '+ _id + ' was successfully created</p>' ;
    document.getElementById("button").innerHTML= '<input type="submit" name="atm" id="atm_submit" value="New ATM" onclick="return new ATM()"/>' ;
} 

// COSTUMER  

var Costumer = function (firstName, lastName) {
    
    var _firstName = firstName;
    
    var _lastName = lastName;
    
    var _fullName = firstName + " " + lastName;
    
    var _id = Math.floor(Math.random()*900000000) + 100000000;
    
    var _password = Math.floor(Math.random()*9000) + 1000;
    
    var accounts = {};   
    
    this.getId = function (){
        return _id;
    };
    
    this.getName = function (){
        return _fullName;
    };
    
    this.getPassword = function (){
        return _password;
    };
    
    this.createAccount = function (initialBalance) {
        var account = new Account (initialBalance);
        accounts[account.getId()] = account;
        return account;
    };
    
    document.write("Thank you Mr. " + _fullName + ", you have been succesfully registered to Bep Bank. Your costumer Id is "+ _id + " and your secret password is " + _password )

}

//ACCOUNT

var Account = function (initialBalance) {
    
    var _id = Math.floor(Math.random()*900000000) + 100000000;
    
    var _currentBalance = initialBalance;
    
    this.getId = function (){
        return _id;
    };
    
    this.getCurrentBalance = function (){
        return _currentBalance;
    };
    
    this.deposit = function (depositAmount) {
        _currentBalance += depositAmount;
        return _currentBalance;
    }
    
    this.withdrawal = function (withdrawalAmount) {
        _currentBalance += withdrawalAmount;
        return _currentBalance;
    }   
    document.write("Your account number " + _id + " has been created with an initial balance of "+ _currentBalance )

}


//new ATM ("Wallstreet 888, Manhattan, New York");


//var sergi = atm1.createCostumer("Sergi", "Gómez");
//
//var sergiAccount1 = sergi.createAccount(3000);







































